<?php
class db {

    function db(){
		// CHANGE THESE TO CORRECT VALUES
		
		global $mysqluser;
		global $mysqlpass;
		global $mysqlhost;
		global $mysqldb;
		
        mysql_connect($mysqlhost, $mysqluser, $mysqlpass) or die("MySQL Connection Failed");
        mysql_select_db($mysqldb) or die("Could Not Select Database");
    }

    function query($sql){
        $result = mysql_query($sql) or die(mysql_error() . "<br>" . $sql);
        return $result;

    }

    function fetch($sql){
        $result = $this->fetch_row($this->query($sql));
        return $result;
    }

    function fetch_row($set){
        $result = mysql_fetch_row($set);
        return $result;

    }

    function fetch_array($set){
        $result = mysql_fetch_array($set);
        return $result;
    }

    function insert_id(){
        $id = mysql_insert_id();
        return $id;

    }

    function dbCall($field, $table="config"){
        list($ret) = $this->fetch_row($this->query("select $field from $table limit 1"));
        return $ret;
    }

    function setting($setting){
        list($ret) = $this->fetch_row($this->query("select value from Config WHERE setting='$setting'"));
        return $ret;
    }

    function num_rows($set){
        $result = mysql_num_rows($set);
        return $result;
    }

    function getCount($table, $where=''){
        $sql = "select count(*) from " . $table;
        if ($where != ''){ $sql .= " where " . $where; }
        list($count) = $this->fetch_row($this->query($sql));
        return $count;
    }

    function getDatabaseDetails(){
	    global $database;
	    $result = $this->query("show table status from $database");
        $size = 0;
        $oh = 0;
        if ($result){
            while( $row = $this->fetch_array($result)){
                $size += $row[Data_length] + $row[Index_length];
                $oh += $row[Data_free];
            }
        }
        $ret[size] = number_format($size/1048576, 2) . " MB";
        $ret[overhead] = $oh . " bytes";
        return $ret;
    }	
}
$db = new db();
?>